use serde::{Deserialize, Serialize};

pub type FamilyMessage = Vec<(String, String, u16)>;

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
#[serde(tag = "type", content = "data")]
pub enum RraiMessage {
    #[serde(rename = "family")]
    Family(FamilyMessage),
}
impl RraiMessage {}

impl From<&String> for RraiMessage {
    fn from(msg: &String) -> Self {
        let msg_str = msg.as_str();
        serde_json::from_str(msg_str).expect("signal message unmarshal")
    }
}

impl From<&RraiMessage> for String {
    fn from(msg: &RraiMessage) -> Self {
        serde_json::to_string(msg).expect("signal message marshal")
    }
}
